package com.bk.controller.balance;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bk.entity.AccountBalance;
import com.bk.entity.CardInfo;
import com.bk.entity.TranFlowInfo;
import com.bk.entity.UserInfo;
import com.bk.service.balance.BalanceService;
import com.bk.util.ReturnUtil;

@RestController /** 金额处理 @author czl */
public class BalanceController {

	@Autowired
	private BalanceService balanceService;

	@PostMapping("/queryAccountBalance") /** 查询账户金额 */
	public ReturnUtil<AccountBalance> queryBalance(@RequestParam("accountId") String accountId,
			@RequestParam("cardPassword") String cardPassword) {
		ReturnUtil<AccountBalance> ru = balanceService.queryBalance(accountId, cardPassword);
		return ru;
	}

	@PostMapping("/saveOrGetBalanceByAccountId/{flag}") /** 存钱或者取钱 通过flag唯一标识确定存钱还是取钱 1存钱 0取钱 */
	public ReturnUtil<AccountBalance> saveOrGetBalanceByAccountId(@PathVariable("flag") int flag, CardInfo cardInfo,
			AccountBalance accountBalance, UserInfo userInfo) {
		ReturnUtil<AccountBalance> ru = balanceService.saveOrGetBalance(flag, cardInfo, accountBalance, userInfo);
		return ru;
	}

	@PostMapping("/transferBalance") /** 转账A to B */
	public ReturnUtil<TranFlowInfo> transferFromAToB(@RequestParam("sendAccount") String sendAccount,
			@RequestParam("sendAccountName") String sendAccountName, @RequestParam("password") String password, @RequestParam("recevieAccount") String recevieAccount,
			@RequestParam("recevieAccountName") String recevieAccountName, @RequestParam("tranBalance") String tranBalance) {
		System.out.println("aaaaa");
		ReturnUtil<TranFlowInfo> transferFromAToB = balanceService.transferFromAToB(sendAccount, sendAccountName, password, recevieAccount, recevieAccountName, tranBalance);
		return transferFromAToB;
	}
	

}
